home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cvs / sprite / collect_sets.c < prev    next >
C/C++ Source or Header  |  1991-09-10  |  8KB  |  307 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Id: collect_sets.c,v 1.2 91/09/10 16:15:16 jhh Exp $";
  3. #endif !lint
  4.  
  5. /*
  6.  *    Copyright (c) 1989, Brian Berliner
  7.  *
  8.  *    You may distribute under the terms of the GNU General Public License
  9.  *    as specified in the README file that comes with the CVS 1.0 kit.
  10.  *
  11.  * Collect Sets
  12.  *
  13.  *    Collects the interesting file names from the administration and
  14.  *    the repository in a number of variables:
  15.  *                            solved by:
  16.  *        Clist    conflict-ridden            (user)
  17.  *        Glist    modified, needs merging        (update)
  18.  *        Mlist    modified, needs checking in    (commit)
  19.  *        Olist    needs checking out        (update)
  20.  *        Alist    to be added            (commit)
  21.  *        Rlist    to be removed            (commit)
  22.  *        Wlist    remove entry            (update)
  23.  *        Llist    locked list            (commit)
  24.  *        Blist    branch list            (commit)
  25.  *        Dlist    directory list            (update)
  26.  *
  27.  *    Returns non-zero on error.
  28.  */
  29.  
  30. #include <sys/param.h>
  31. #include "cvs.h"
  32.  
  33. extern char update_dir[];
  34.  
  35. Collect_Sets(argc, argv)
  36.     int argc;
  37.     char *argv[];
  38. {
  39.     register int i;
  40.     char tmp[MAXPATHLEN], update_user[MAXPATHLEN];
  41.     int ret = 0;
  42.  
  43.     /*
  44.      * By default, a call here must wipe the slate clean
  45.      */
  46.     Clist[0] = Glist[0] = Mlist[0] = Olist[0] = Dlist[0] = '\0';
  47.     Alist[0] = Rlist[0] = Wlist[0] = Llist[0] = Blist[0] = '\0';
  48.     for (i = 0; i < argc; i++) {
  49.     (void) strcpy(User, argv[i]);
  50.     if (update_dir[0] != '\0')
  51.         (void) sprintf(update_user, "%s/%s", update_dir, User);
  52.     else
  53.         (void) strcpy(update_user, User);
  54.     if (force_tag_match && (Tag[0] != '\0' || Date[0] != '\0'))
  55.         Locate_RCS();
  56.     else
  57.         (void) sprintf(Rcs, "%s/%s%s", Repository, User, RCSEXT);
  58.     if (isdir(User)) {        /* just a directory -- add to Dlist */
  59.         (void) strcat(Dlist, " ");
  60.         (void) strcat(Dlist, User);
  61.         continue;
  62.     }
  63.     Version_TS(Rcs, Tag, User);
  64.     if (VN_User[0] == '\0') {
  65.         /*
  66.          * No entry available, TS_Rcs is invalid
  67.          */
  68.         if (VN_Rcs[0] == '\0') {
  69.         /*
  70.          * There is no RCS file either
  71.          */
  72.         if (TS_User[0] == '\0')    { /* there is no user file */
  73.             if (!force_tag_match || !isfile(Rcs)) {
  74.             warn(0, "nothing known about %s", update_user);
  75.             ret++;
  76.             }
  77.         } else {        /* there is a user file */
  78.             if (!force_tag_match) {
  79.             warn(0, "use `cvs add' to create entry for %s",
  80.                  update_user);
  81.             ret++;
  82.             }
  83.         }
  84.         } else {
  85.         /*
  86.          * There is an RCS file
  87.          */
  88.         if (TS_User[0] == '\0') {
  89.             /*
  90.              * There is no user file; ad it to the Olist
  91.              */
  92.             (void) strcat(Olist, " ");
  93.             (void) strcat(Olist, User);
  94.         } else {
  95.             /*
  96.              * There is a user file; print a warning and add it
  97.              * to the conflict list, Clist, only if it is indeed
  98.              * different from what we plan to extract
  99.              */
  100.             No_Difference(0);
  101.             if (strcmp(TS_Rcs, TS_User) == 0) {
  102.             (void) strcat(Olist, " ");
  103.             (void) strcat(Olist, User);
  104.             } else {
  105.             warn(0, "move away %s; it is in the way",
  106.                  update_user);
  107.             (void) strcat(Clist, " ");
  108.             (void) strcat(Clist, User);
  109.             ret++;
  110.             }
  111.         }
  112.         }
  113.     } else if (VN_User[0] == '0' && VN_User[1] == '\0') {
  114.         /*
  115.          * An entry for a new-born file; TS_Rcs is dummy
  116.          */
  117.         if (TS_User[0] == '\0') {
  118.         /*
  119.          * There is no user file, but there should be one;
  120.          * add it to the remove entry list.
  121.          */
  122.         warn(0, "warning: new-born %s has disappeared", update_user);
  123.         (void) strcat(Wlist, " ");
  124.         (void) strcat(Wlist, User);
  125.         } else {
  126.         /*
  127.          * There is a user file
  128.          */
  129.         if (VN_Rcs[0] == '\0') {
  130.             /*
  131.              * There is no RCS file, so add it to the add entry list
  132.              */
  133.             (void) strcat(Alist, " ");
  134.             (void) strcat(Alist, User);
  135.         } else {
  136.             /*
  137.              * There is an RCS file, so someone else must have
  138.              * checked one in behind our back; added to the conflict
  139.              * list
  140.              */
  141.             warn(0, "conflict: %s created independently by second party",
  142.              update_user);
  143.             (void) strcat(Clist, " ");
  144.             (void) strcat(Clist, User);
  145.             ret++;
  146.         }
  147.         }
  148.     } else if (VN_User[0] == '-') {
  149.         /*
  150.          * An entry for a removed file, TS_Rcs is invalid
  151.          */
  152.         if (TS_User[0] == '\0') {
  153.         /*
  154.          * There is no user file (as it should be)
  155.          */
  156.         (void) sprintf(tmp, "-%s", VN_Rcs);
  157.         if (strcmp(tmp, "-") == 0) {
  158.             /*
  159.              * There is no RCS file; this is all-right, but it
  160.              * has been removed independently by a second party;
  161.              * added to the remove entry list.
  162.              */
  163.             (void) strcat(Wlist, " ");
  164.             (void) strcat(Wlist, User);
  165.         } else if (strcmp(tmp, VN_User) == 0) {
  166.             /*
  167.              * The RCS file is the same version as the user file,
  168.              * and that's OK; added to the to be removed list
  169.              */
  170.             (void) strcat(Rlist, " ");
  171.             (void) strcat(Rlist, User);
  172.         } else {
  173.             /*
  174.              * The RCS file is a newer version than the user file;
  175.              * and this is defintely not OK; make it a conflict.
  176.              */
  177.             warn(0, "conflict: removed %s was modified by second party",
  178.              update_user);
  179.             (void) strcat(Clist, " ");
  180.             (void) strcat(Clist, User);
  181.             ret++;
  182.         }
  183.         } else {
  184.         /*
  185.          * The user file shouldn't be there
  186.          */
  187.         warn(0, "%s should be removed and is still there", update_user);
  188.         ret++;
  189.         }
  190.     } else {
  191.         /*
  192.          * A normal entry, TS_Rcs is valid
  193.          */
  194.         if (VN_Rcs[0] == '\0') {
  195.         /*
  196.          * There is no RCS file
  197.          */
  198.         if (TS_User[0] == '\0') {
  199.             /*
  200.              * There is no user file, so just remove the entry
  201.              */
  202.             warn(0, "warning: %s is not (any longer) pertinent",
  203.              update_user);
  204.             (void) strcat(Wlist, " ");
  205.             (void) strcat(Wlist, User);
  206.         } else if (strcmp(TS_User, TS_Rcs) == 0) {
  207.             /*
  208.              * The user file is still unmodified, so just remove it
  209.              * from the entry list
  210.              */
  211.             if (!force_tag_match || !isfile(Rcs)) {
  212. #if 0
  213.             warn(0, "%s is no longer in the repository",
  214.                  update_user);
  215. #endif
  216.             (void) strcat(Wlist, " ");
  217.             (void) strcat(Wlist, User);
  218.             }
  219.         } else {
  220.             /*
  221.              * The user file has been modified and since it is no
  222.              * longer in the repository, a conflict is raised
  223.              */
  224.             if (!force_tag_match) {
  225.             Locate_RCS();
  226.             (void) No_Difference(0);
  227.             if (strcmp(TS_User, TS_Rcs) == 0) {
  228.                 warn(0,
  229.         "warning: %s is not (any longer) pertinent",
  230.                  update_user);
  231.                 (void) strcat(Wlist, " ");
  232.                 (void) strcat(Wlist, User);
  233.             } else {
  234.                 warn(0,
  235.         "conflict: %s is modified but no longer in the repository",
  236.                  update_user);
  237.                 (void) strcat(Clist, " ");
  238.                 (void) strcat(Clist, User);
  239.                 ret++;
  240.             }
  241.             }
  242.         }
  243.         } else if (strcmp(VN_Rcs, VN_User) == 0) {
  244.         /*
  245.          * The RCS file is the same version as the user file
  246.          */
  247.         if (TS_User[0] == '\0') {
  248.             /*
  249.              * There is no user file, so note that it was lost
  250.              * and extract a new version
  251.              */
  252.             if (strcmp(command, "checkout") != 0 &&
  253.             strcmp(command, "co") != 0 &&
  254.             strcmp(command, "get") != 0)
  255.             warn(0, "warning: %s was lost", update_user);
  256.             (void) strcat(Olist, " ");
  257.             (void) strcat(Olist, User);
  258.         } else if (strcmp(TS_User, TS_Rcs) == 0) {
  259.             /*
  260.              * The user file is still unmodified, so nothing
  261.              * special at all to do -- no lists updated
  262.              */
  263.         } else {
  264.             /*
  265.              * The user file appears to have been modified, but
  266.              * we call No_Difference to verify that it really
  267.              * has been modified -- it updates the Mlist,
  268.              * if necessary.
  269.              */
  270.             (void) No_Difference(0);
  271.         }
  272.         } else {
  273.         /*
  274.          * The RCS file is a newer version than the user file
  275.          */
  276.         if (TS_User[0] == '\0') {
  277.             /*
  278.              * There is no user file, so just get it
  279.              */
  280.             if (strcmp(command, "checkout") != 0 &&
  281.             strcmp(command, "co") != 0 &&
  282.             strcmp(command, "get") != 0)
  283.             warn(0, "warning: %s was lost", update_user);
  284.             (void) strcat(Olist, " ");
  285.             (void) strcat(Olist, User);
  286.         } else if (strcmp(TS_User, TS_Rcs) == 0) {
  287.             /*
  288.              * The user file is still unmodified, so just get it
  289.              * as well
  290.              */
  291.             (void) strcat(Olist, " ");
  292.             (void) strcat(Olist, User);
  293.         } else {
  294.             /*
  295.              * The user file appears to have been modified; we call
  296.              * No_Difference to verify this for us, and it updates
  297.              * Glist if it has really been modified, and Olist if
  298.              * it hasn't
  299.              */
  300.             (void) No_Difference(1);
  301.         }
  302.         }
  303.     }
  304.     }
  305.     return (ret);
  306. }
  307.